﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PSLib.Parsing.Common.Search
{
    public abstract class QParam
    {
        #region Static members

        public static readonly QParam Any = new QParamAny();
        
        public static QParam Create(RecognizedTokenType type, bool select = false) { return QParam.Select(new QParamLogicType(type),select); }
        public static QParam Create(string text, bool select = false) { return QParam.Select(new QParamText(text), select); }
        
        /*public static QParam GetWild(int )
        {
            param.Select = select;
            return param;
        }*/
        public static QParam Select(QParam param, bool select) 
        {
            param.Selectable = select;
            return param;
        }

        #endregion

        #region Constructor

        public QParam()
        {
            this.Selectable = false;
        }

        #endregion

        #region Virtual members

        public abstract bool Compare(RecognizedToken token);

        #endregion

        #region Properties

        public bool Selectable { get; set; }

        #endregion
    }

    internal class QParamLogicType : QParam
    {
        public QParamLogicType(RecognizedTokenType type)
        {
            this.Type = type;
        }
        public override bool Compare(RecognizedToken token)
        {
            return token.Type == this.Type;
        }
        public RecognizedTokenType Type { get; set; }
    }

    internal class QParamText : QParam
    {
        public QParamText(string text)
        {
            this.Text = text;
        }

        public override bool Compare(RecognizedToken token)
        {
            return token.NativeToken.Text == this.Text;
        }
        public string Text { get; set; }
    }

    public class QParamAny : QParam
    {
        public QParamAny()
        {
        }
        public override bool Compare(RecognizedToken token)
        {
            return true;
        }
    }
}
